#include "../include/common.h"
#include <stdarg.h>

const char *level_tab[4] = {"D", "I", "W", "E"};
const char *color_tab[4] = {"\033[0m", "\033[32m", "\033[33m", "\033[31m"};

// probe: 分类名称
// level: 打印等级
void log_print(char *probe, int level, const char *format, ...)
{

    char stime[30] = "";
    util_hw_get_systime(stime);
    char prefix[100] = "";
    sprintf(prefix, "%s [%s/%s] ", stime, probe, level_tab[level]);

    char print_buf[LOG_PAYLOAD_LEN] = "";
    va_list args;
    va_start(args, (char *)format);
    vsnprintf(print_buf, LOG_PAYLOAD_LEN, format, args);
    va_end(args);

    char log[LOG_PAYLOAD_LEN + LOG_PREFIX_LEN] = "";
    strcat(log, prefix);
    strcat(log, print_buf);

    printf("%s", color_tab[level]);
    printf("%s", log);
    printf("\033[0m\n");
}
